/**
 * 
 */
package com.google.code.maven.plugin.http.client.config;

import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import com.google.code.maven.plugin.http.client.RequestParameter;

/**
 * RequestParameterConfiguration
 * 
 * @author Nadim Benabdenbi
 * @version 1.0
 * @since JDK1.6
 */
public class RequestParameterConfiguration extends RequestParameter {

	protected static final AtomicInteger id = new AtomicInteger();

	public RequestParameter build(DefaultListableBeanFactory factory) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(RequestParameter.class);
		String beanId = RequestParameter.class.getSimpleName() + id.incrementAndGet();
		builder.addPropertyValue("name", getName());
		builder.addPropertyValue("value", getValue());
		factory.registerBeanDefinition(beanId, builder.getBeanDefinition());
		return factory.getBean(beanId, RequestParameter.class);
	}
}
